#ifndef MPLAYERCONTROLLER_H
#define MPLAYERCONTROLLER_H

#include <QObject>
#include <QRect>
#include <QProcess>

class MPlayerController : public QObject
{
    Q_OBJECT

public:
    enum State{PlayingState,PausedState,StoppedState,ErrorState,DefaultState};
    MPlayerController(QObject *parent = 0);
    ~MPlayerController();
    bool startMPlayer(QString szPath,QRect playerRect,int position = 0,int volume = 100);
    bool stopMPlayer();
    bool playOrPauseMPlayer();

    enum State getCurrentState();
private slots:
    void catchMPlayerOutput();
public slots:
    bool requestCurrentTimePosition();
    void seek(int sec);
    void mediaEnd(int exitCode, QProcess::ExitStatus exitStatus);
    void setVolume(int volume);
private:
    QProcess *mplayerProcess;
    void setCurrentState(enum State);
    enum State currentState;
signals:
    void totalTimeReceived(int sec);
    void currentTimePositionReceived(int sec);
    void stateChanged(enum MPlayerController::State);
};

#endif // MPLAYERCONTROLLER_H
